<?php
/**
 * Created by PhpStorm.
 * Admininfo: Administrator
 * Date: 2017/12/6
 * Time: 12:03
 */

namespace app\admin\controller;
use app\common\controller\Curt;
use think\Config;
use think\Db;
use app\admin\model\Admingroup;
class Admininfo extends Curt
{
	function __construct()
	{
		parent::__construct($upload = true,$uploadConfig = array(
			'input_name' => 'coverFile',//文本框name
			'data_field' => 'cover'//数据库字段
		));
	}
	public function getall()
    {
           $keyword=input('get.keyword');
            if($keyword){
                $where['name']=['like','%'.$keyword.'%'];//模糊查询or可以一个条件中写多个字段以‘|’分开
            }else{
                $where['name']=['neq',' '];
            }
        $del=input('?get.del');
        if($del){
             $list=$this->model->onlyTrashed()->paginate();
        }else{
             $list = $this->model
                   ->alias('a')
                   ->join(['ec_admingroup'=>'b'],'a.user_group_id=b.     id','left')
                   ->order('id desc')
                   ->field('a.*,ec_admingroup.title')
                   -> where($where)->paginate();
        }

        $page = $list->render();
        $this->assign('list', $list);
        $this->assign('page', $page);
    }
    public function editAfter($data)
    {
        if(!$data['pass']){
            unset($data['pass']);
        }
        return $data;
    }
    public function showAdd()
    {
        $this->getmenulist();
        return parent::showAdd(); // TODO: Change the autogenerated stub
    }

    /**
     * @return \think\response\Json
     * 重置密码
     */
    public function referpass(){
        $where['id']=input('id');
        $this->model->isUpdate(true)->save($where);
        return json(['status'=>1]);
    }

    /**
     * @return \think\response\Json
     * 开启关闭状态
     */
    public function editstatus(){
        $where['id']=input('id');
        $status=input('status');
        if($status==1){
            $status=-1;
        }else{
            $status=1;
        }
        $where['status']=$status;
        $this->model->isUpdate(true)->save($where);
        if($status==-1){
            $res['msg']="用户已关闭！";
        }else{
            $res['msg']="用户已开启！";
        }
        return json($res);
    }
    public function showEdit($id)
    {
        $this->getmenulist();
        return parent::showEdit($id); // TODO: Change the autogenerated stub
    }

}